package com.ntschy.web.controller.bt;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ntschy.bt.entity.dataobject.BtPolicy;
import com.ntschy.bt.entity.dto.btPolicyDTO.BtPolicyOverviewPageDTO;
import com.ntschy.bt.entity.mapstruct.BtPolicyMapstruct;
import com.ntschy.bt.service.IBtPolicyOverviewService;
import com.ntschy.common.core.AjaxPageResult;
import com.ntschy.common.core.AjaxResult;
import com.ntschy.common.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bt/policy")
@Api(tags = "政策一览接口")
@Validated
public class BtPolicyOverviewController extends BaseController {
    @Autowired
    private IBtPolicyOverviewService overviewService;

    /**
     * 政策一览 审核通过列表
     *
     * @param overviewPageDTO
     * @return
     */
    @ApiOperation(value = "政策一览 审核通过列表", notes = "")
    @ApiImplicitParam(name = "overviewPageDTO", value = "政策一览 审核通过列表", required = true, dataType = "BtPolicyOverviewPageDTO")
    @PostMapping("/pageOverviewPolicy")
    public AjaxPageResult<BtPolicy> selectByExamineResult(@RequestBody BtPolicyOverviewPageDTO overviewPageDTO){
        Page<BtPolicy> page = PageHelper.startPage(overviewPageDTO.getCurrPage(), overviewPageDTO.getPageSize());
        BtPolicy queryBtPolicy = BtPolicyMapstruct.BT_POLICY_MAP_STRUCT.pageOverviewPolicy(overviewPageDTO);
        List<BtPolicy> list = overviewService.selectByExamineResult(queryBtPolicy);
        return buildPageResult(list,page);
    }

    /**
     * 查询政策详情信息  根据ID
     */
    @ApiOperation(value = "查询政策详情信息  根据ID", notes = "")
    @ApiImplicitParam(name = "id", value = "查询政策详情信息  根据ID", required = true, dataType = "BtPolicyOverviewPageDTO")
    @GetMapping("/fetchOverviewPolicy/{id}")
    public AjaxResult selectOverviewById(@PathVariable String id){
        BtPolicy btPolicy1 = overviewService.selectOverviewPolicyById(id);
        return AjaxResult.success("查询成功",btPolicy1);
    }
}
